package com.exam.controller;

import com.exam.pojo.Admin;
import com.exam.service.AdminServcie;
import com.exam.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminServcie adminServcie;
    @GetMapping("/{adminid}")
    public Result find(@PathVariable("adminid") Integer adminid){
        return new Result(true,adminServcie.findById(adminid));
    }

    @PostMapping
    public Result insert(@RequestBody Admin admin){
        int i = adminServcie.insertById(admin);
        if(i>0){
            return new Result(true,"增加成功");
        }else{
            return new Result(false,"增加失败");
        }
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Integer id){
        int i = adminServcie.deleteById(id);
        if(i>0){
            return new Result(true,"删除成功");
        }else{
            return new Result(false,"删除失败");
        }
    }

    @PutMapping
    public Result update(@RequestBody Admin admin){
        int i = adminServcie.updateById(admin);
        if(adminServcie.updateById(admin)>0){
            return new Result(true,"修改成功");
        }else{
            return new Result(false,"修改失败");
        }
    }

    @GetMapping
    public Result findAll(){
        return new Result(true,adminServcie.getAdminAll());
    }
}
